﻿namespace NJQuery {
	using System;
	using System.Web.UI;
	using System.ComponentModel;

	/// <summary>
	/// Server control used to generate a jQuery UI <see cref="Accordion"/> animation script.
	/// </summary>
	[ParseChildren(true), PersistChildren(false)]
	public class AccordionAnimationDef : AnimationDef {


		#region Constructors

		/// <summary>
		/// Initializes a new instance of the <see cref="AccordionAnimationDef"/> class.
		/// </summary>
		public AccordionAnimationDef() { }

		#endregion


		#region Methods: Rendering hooks

		/// <summary>
		/// Allows a jQuery server control to reference scripts and stylesheets necessary to render their client markup and widgets.
		/// </summary>
		/// <param name="manager">The <see cref="Manager"/> used to handle style and script referencing in addition to unified generation of load and ready scripts.</param>
		protected override void Register(Manager manager) {

			manager.RegisterClientScript(ClientScript.Core);
			manager.RegisterClientScript(ClientScript.UIWidgetFactory);
			manager.RegisterClientScript(ClientScript.UIAccordionWidget);

			manager.RegisterForReadyScript(this);
		}

		/// <summary>
		/// Renders the jQuery "Ready Event" script required to generate the client-side jQuery widget.
		/// This method is used primarily by control developers.
		/// </summary>
		/// <param name="script">A <see cref="ScriptBuilder"/> that creates the output stream to render jQuery JavaScript on the client.</param>
		protected override void RenderReadyScript(ScriptBuilder script) {

			script.Append("$.ui.accordion.animations.");
			script.Append(Name);
			script.Append(" = function(options) {");

			script.Indent++;
			script.NewLine();

			script.Append(Definition);

			script.Indent--;
			script.NewLine();

			script.Append("};");
		}

		#endregion


	}

}